import { getUsersByName } from "../api/github"
export default {
  async searchFn(store, val) {
    if (!store.state.name) {
      store.commit('nameSign', true)
      return;
    }
    store.dispatch("sendName");
    store.commit('nameSign', false)
    //清空输入框
    store.commit('dataName', '')
  },

  async sendName(store) {
    try {
      store.commit('beforeReq');
      const { items } = await getUsersByName(store.state.name) //发送请求
      store.commit('add', items)

      if (items.length > 0) {
        //发送请求成功 且拥有数据

        store.commit('afterReqSuccessHasBody')
      } else {
        //发送请求成功 没有数据

        store.commit('afterReqSuccessNoBody')
      }
    } catch (e) {

      store.commit.afterReqFail()
    }
  },
}
